
import { request } from "@/utils/request"
let sha256 = require("js-sha256").sha256
export function syncToCloud(option) {

    option.url = 'path=/api/cfg/syncByEdge/' + option.edgeID;
    return proxyToCloud(option,'put');
}


export function proxyToCloud({ things, pd, un, addr, url }, method) {
    let rurl = "api/cfg/cloud/proxy?un=" + un + "&pd=" + sha256(pd) +
        "&addr=" + addr + "&" + url;
    if (method == 'get' || method == 'delete') {
        return request(rurl, method);
    } 
    return request(rurl, method,things);
    

}

export function getCloudStations({  pd, un, addr }) {
    return proxyToCloud({things:[],  pd, un, addr, url: 'path=api/cfg/station/' }, 'get')
}

export default (
    syncToCloud,
    proxyToCloud,
    getCloudStations
)